<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 
   key:是为了vue做虚拟dom对比时更加高效，最终让渲染更加高效
   语法：:key='字符串、数字'  
   使用场景  v-for    一定要配上key,优先级，有id优先用id,没有就使用index
   虚似dom对比：更高效渲染
     旧dom
       ul
         li  张三  key='1'
         li  李四  key='2'
      新dom
       ul
         li  王五
         li  张三   key='1'
         li  李四   key='2'
 -->

    <div id="app">
      <h1 id="h1">123456</h1>
      <button @click="bol=!bol">点击切换</button>
      <div v-if="bol" key="1">
        <span>用户名</span>
        <input type="text" placeholder="请输入用户名" />
      </div>
      <div v-else key="2">
        <span>密码</span>
        <input type="text" placeholder="请输入密码" />
      </div>
      <div>xxx</div>
      <div>123</div>
      <div v-for="(item, index) in items" :key="index">{{item}}</div>
      <div key="0">1</div>
      <div key="1">2</div>
      <div key="2">3</div>
      <div key="3">4</div>
      <!-- 
<div key="0">0</div>
<div key="1">1</div>
<div key="2">2</div>
<div key="3">3</div>
<div key="4">4</div> -->
    </div>
    <script src="./vue.js"></script>
    <script>
      new Vue({
        el: '#app',
        data: {
          bol: true,
          items: [{ id: 0 }, { id: 1 }, { id: 2 }, { id: 3 }] //  ==>items: [{id:-1},{id:0}, {id:1}, {id:2}, {id:3}]
        }
      })
    </script>
  </body>
</html>
